/*
 * Alberto Ruiz-Larrea Guillén...11383
 * Erdi Dogruel..................14955
 * Marcos Pérez Martín...........10324
 */

package com.example.database;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.util.Log;

//This class inserts a new team in leaderboard table in database
public class InsertTeamLeaderBoard extends AsyncTask<String, Integer, Long> {

	private OpenDB open;

	public InsertTeamLeaderBoard(OpenDB op) {
		open = op;
	}

	@Override
	protected Long doInBackground(String... params) {
		final String name = params[0];
		final String games_played = params[1];
		final String won_matches = params[2];
		final String draw_matches = params[3];
		final String lost_matches = params[4];
		final String points = params[5];

		SQLiteDatabase db = open.getWritableDatabase();

		ContentValues values = new ContentValues();
		values.put(OpenDB.name, name);
		values.put(OpenDB.games_played, games_played);
		values.put(OpenDB.won_matches, won_matches);
		values.put(OpenDB.draw_matches, draw_matches);
		values.put(OpenDB.lost_matches, lost_matches);
		values.put(OpenDB.points, points);

		return db.insert(OpenDB.table4, null, values);
	}

	@Override
	protected void onPostExecute(Long result) {
		if (result == -1) {
			Log.e("Insert", "Error while insert team in table leaderboard DB");
		}
	}
}
